package org.songwang.basic.controller;

import com.sun.xml.internal.ws.util.FastInfosetUtil;
import org.songwang.basic.AjaxResult;
import org.songwang.basic.FastDfsUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/fastdfs")
public class FastDfsController {
    @RequestMapping("/upload")
    public AjaxResult upload(MultipartFile file){
        try {
            System.out.println(file);
//        获取上传文件的大小
            System.out.println(file.getSize());
//        获取上传文件的原始文件名
            System.out.println(file.getOriginalFilename());
//            获取fastdfs存储的路径
            String path = FastDfsUtil.upload(file.getBytes(), "jpg");
            System.out.println(path);
            return AjaxResult.me();
        } catch (IOException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("操作失败").setSuccess(false);
        }
    }
}
